//package com.example.shiwu;
//
//import android.annotation.SuppressLint;
//import android.app.ActionBar;
//import android.app.Activity;
//import android.app.AlertDialog;
//import android.content.Context;
//import android.content.DialogInterface;
//import android.content.SharedPreferences;
//import android.content.res.Resources;
//import android.database.Cursor;
//import android.database.sqlite.SQLiteDatabase;
//import android.graphics.Bitmap;
//import android.graphics.BitmapFactory;
//import android.os.Bundle;
//import android.os.Environment;
//import android.os.Handler;
//import android.os.HandlerThread;
//import android.os.Message;
//import android.os.StrictMode;
//import android.view.Gravity;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.WindowManager;
//import android.widget.EditText;
//import android.widget.ImageView;
//import android.widget.ListView;
//import android.widget.PopupWindow;
//import android.widget.Spinner;
//import android.widget.TextView;
//import android.widget.Toast;
//
//import androidx.appcompat.app.AppCompatActivity;
//
//import com.chaquo.python.PyObject;
//import com.chaquo.python.Python;
//import com.chaquo.python.android.AndroidPlatform;
//import com.example.shiwu.db.dao.DeviceDao;
//import com.example.shiwu.db.model.Alarm;
//import com.example.shiwu.db.model.Arrange;
//import com.example.shiwu.db.model.Device;
//import com.example.shiwu.db.model.Items;
//import com.example.shiwu.db.model.Sends;
//import com.example.shiwu.db.vo.MyQueue;
//import com.example.shiwu.manager.DatabaseHelper;
//import com.example.shiwu.service.AlarmService;
//import com.example.shiwu.service.ArrangeService;
//import com.example.shiwu.service.BoxEightService;
//import com.example.shiwu.service.BoxFiveService;
//import com.example.shiwu.service.BoxFourService;
//import com.example.shiwu.service.BoxNineService;
//import com.example.shiwu.service.BoxOneService;
//import com.example.shiwu.service.BoxSevenService;
//import com.example.shiwu.service.BoxSixService;
//import com.example.shiwu.service.BoxTenService;
//import com.example.shiwu.service.BoxThreeService;
//import com.example.shiwu.service.BoxTwoService;
//import com.example.shiwu.service.DeviceService;
//import com.example.shiwu.service.ItemsService;
//import com.example.shiwu.service.ReceiveService;
//import com.example.shiwu.service.ReceiveVolEleService;
//import com.example.shiwu.service.SendsService;
//import com.example.shiwu.util.ArrayUtil;
//import com.example.shiwu.util.ContextVariable;
//import com.example.shiwu.util.DataParseUtil;
//import com.example.shiwu.util.DateUtils;
//import com.example.shiwu.util.FileDownUtil;
//import com.example.shiwu.util.SocketUtils;
//import com.google.firebase.crashlytics.buildtools.reloc.com.google.common.base.Joiner;
//
//import org.json.JSONException;
//
//import java.io.File;
//import java.io.FileNotFoundException;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.text.SimpleDateFormat;
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//import cn.hutool.core.util.IdUtil;
//
//public class SendReceiveAddBackNewActivity extends AppCompatActivity {
//
//    private DeviceService deviceService;
//    private ItemsService itemsService;
//    private ReceiveService receiveService;
//    private Map<String, Object> showitem;
//    private List<Map<String, Object>> listitem;
//    private ArrayList<Device> deviceLisAll = new ArrayList<Device>();
//
//    private int currentPage = 0;
//    private int pageSize = 2;
//    private int totalSize = 0;
//    public ListView editSb;
//    public TextView title_text, title_seting, send_sub_btn;
//    public ImageView title_back;
//    private boolean checkSta = false;
//    private DatabaseHelper dbHelper;
//    private DeviceDao deviceDao;
//    private Context myContext;
//    private TextView pop_close;
//    public int startCount = 0;
//    private EditText send_voltage_val, send_repeat_val, send_duration_val,
//            send_point_a_val, send_point_b_val, send_point_m_val, send_point_n_val, clear_all_mux_box_connect_val;
//    private Spinner send_frequency_val;
//    private PopupWindow mPopWindow;
//    private SendsService sendsService;
//    private AlarmService alarmService;
//    private ArrangeService arrangeService;
////    private TextView pop_close;
//
//    private final String TAG = "SendReceiveActivity";
//    private static final String IP_ADDRESS = "ip_address";
//    private static final String CLIENT_PORT = "client_port";
//    private static final String CLIENT_MESSAGETXT = "client_msgtxt";
//
//
//    private HandlerThread mHandlerThread;
//    //子线程中的Handler实例。
//    private Handler mSubThreadHandler;
//
//    private final int STATE_DISCONNECTED = 1;
//    private final int STATE_CONNECTING = 2;
//    private final int STATE_CONNECTED = 3;
//    private SharedPreferences mSharedPreferences;
//    private SharedPreferences.Editor editor;
//    private int mSocketConnectState = STATE_DISCONNECTED;
//
//    private static final int MSG_TIME_SEND = 1;
//    private static final int MSG_SOCKET_CONNECT = 2;
//    private static final int MSG_SOCKET_DISCONNECT = 3;
//    private static final int MSG_SOCKET_CONNECTFAIL = 4;
//    private static final int MSG_RECEIVE_DATA = 5;
//    private static final int MSG_SEND_DATA = 6;
//    private static final int MSG_SEND_DATA_BYTE = 7;
//    private static final int MSG_RECEIVE_TU_DATA = 8;
//    private static final int MSG_RECEIVE_TU_NEW_DATA = 9;
//    private static final int MSG_RECEIVE_POP_DATA = 10;
//
//    private static final int MSG_SEND_DATA_BYTE_RECEIVE = 1;//硬件成功返回信息
//    private TextView receive_voltage;
//    private Python py;
//    private PyObject pyobj, pyobj1, pyplot, pyobj2, pyobj3, pyobjfft;
//    private byte[] bytesData;
//    private byte[] data, data2, data3;
//    private Boolean startGater = false;
//    private Boolean errorRepeat = false;
//    private long timeouts = 8000;
//
//    private Integer rx_voltage_data_len = 0;
//    private String simpleUUID = "";
//    private String itemsId;
//    private String sf = "";
//    private String fileName = "";
//    private Integer cvs_line = 0;
//    private Integer rec_count_s = 0;
//    private Integer packet_indx = 0;
//    private int packet_indx1 = 0;
//    private Integer old_packet_lens = 0;
//    private Integer packet_lens = 0;//总包数 1536倒计数到0 packet_lens=0, bak_packet_lens=512, rec_count=512 self.send("kConfirm",rec_count)
//    //private Integer bak_packet_lens = 0; //1536倒计数 bak_packet_lens=512, rec_count=512 self.send("kConfirm",rec_count)
//    private int packet_lens_old = 0;
//    private int receive_count = 0;//用与截取0，success;10,1,10;的标识
//    public int length_byte = 0;//合并Byte
//    //private String no_id_str = "";//不包含数据头 10.1024,12
//    public byte[] all_byte;
//    public byte[] all_byte_de_weight; //去/,后的byte[]
//    public String receiveDataAll = "";
//    public ArrayList<byte[]> all_byte_lis;
//    public int count_byte = 0;
//    public int byte_len = 0;
//    private String cmd_index_len = "";//消息的id 10
//    private boolean next_sta = false;
//    private boolean back_over = false; //biaoshi
//    private boolean byte_sta = false;//组装数据用，完全组装后 true
//    private View contentView;
//    private String tx_voltage = "";//发送电压
//    private String tx_current = "";//发射电流
//    private String rx_voltage = "";//接受电压
//    private ImageView mChart1;
//    private TextView send_voltage_pop_val, send_repeat_pop_val, send_freq_pop_val, receive_duration_pop_val;
//    private String strData;//接收总数据数据，拼接完整数据后再解析
//    private StringBuffer stringBufferData;//接收总数据数据，拼接完整数据后再解析
//
//    private Boolean bl = false;
//
//    private Boolean bool = false;
//    private String[] freqData;
//    private int header_cou = 0;
//    private int loding_count = 0;
//    private String sta = "";
//    private int success_count = 0;
//    private int receive_packet_indx_count = 0;
//    //private Boolean bool1 = true;
//    private int abmn_indx = 0;
//    private byte[] buffer_new = new byte[1];
//    private boolean read_byte_sta = false;
//    private MyQueue queue, queueMsg;
//    private int msg_sueecss_count = 0;
//    public Boolean receive_one_field_sta = true;
//    Boolean returnSta = true;
//    Boolean errorCount = true;
//
//    //private int indx=0;
//    private String tx_voltage_data = "";
//    private String tx_current_data = "";
//    private String rx_voltage_data = "";
//    private StringBuffer rx_voltage_data1;
//    private StringBuffer rx_voltage_data_all1;
//    private ArrayList<String> boxLatLon;
//    private String vol_ele_noindx = "";
//    private String vol_ele = ContextVariable.vol_ele;
//    private Boolean receive_sta = false;//采集一次后true 过滤vol_ele的title
//    private int inclickGatherCount;//点击采集按钮次数
//    private ReceiveVolEleService receiveVolEleService;
//    private SocketUtils socketUtils;
//    private String dtype, shape, abmn;
//    private int dtypelen, dtypelen0, abmnLen, boxId, boxInx;
//    private String[] clearStrLisAll;
//    public MyThread myThread;
//    public Boolean recv_float_bool = false;
//    public Boolean errorSta = false;
//    public Boolean boolErr = true;
//    public Boolean recv_float_bool2 = true;
//    public Boolean anewSta = true;
//    private String rx_voltage_data_all = "";
//    private DataParseUtil dataParseUtil;
//    private ArrayList<String> alis = null;
//
//    private BoxOneService boxOneService;
//    private BoxTwoService boxTwoService;
//    private BoxThreeService boxThreeService;
//    private BoxFourService boxFourService;
//    private BoxFiveService boxFiveService;
//    private BoxSixService boxSixService;
//    private BoxSevenService boxSevenService;
//    private BoxEightService boxEightService;
//    private BoxNineService boxNineService;
//    private BoxTenService boxTenService;
//    private Handler mHandler = new Handler() {
//        public void handleMessage(Message msg) {
//            switch (msg.what) {
//                case MSG_TIME_SEND:
//                    break;
//
//                case MSG_RECEIVE_DATA:
//                    break;
//                case MSG_RECEIVE_TU_DATA://采集数据展示图形
//
//                    //生成的是不带-的字符串，类似于：b17f24ff026d40949c85a24f4f375d42
//                    //String simpleUUID = IdUtil.simpleUUID();
//                    String obj1 = (String) msg.obj;
//                    byte[] ios = obj1.getBytes();
//                    //String pyBytes = dataParseUtil.jb2pb(ios);
//                    byte[] data1 = pyobjfft.callAttr("draw_fft_square_wave", obj1, sf, rx_voltage_data_len).toJava(byte[].class);
//                    mChart1.setImageBitmap(BitmapFactory.decodeByteArray(data1, 0, data1.length));
//                    savebitmap(BitmapFactory.decodeByteArray(data1, 0, data1.length), "niduan");
//                    savebitmap(BitmapFactory.decodeByteArray(data1, 0, data1.length), "pailie");
//                    savebitmap(BitmapFactory.decodeByteArray(data1, 0, data1.length), "boxing");
//                    savebitmap(BitmapFactory.decodeByteArray(data1, 0, data1.length), "pinpu");
////                    new Thread(new Runnable() {
////                        @Override
////                        public void run() {
////                            String[] vel = vol_ele.split(";");
////                            FileDownUtil.saveFile(myContext, vel, simpleUUID);
////                            queue = new MyQueue();
////                            List<ReceiveVolEle> lis = new ArrayList<ReceiveVolEle>();
////                            ReceiveVolEle rve = null;
////                            MyQueue queue1 = new MyQueue();
////                            int ii = 0;
////                            if (!receive_sta) {
////                                ii = 1;
////                            }
////                            for (int i = ii; i < vel.length; i++) {
////                                String vel_new = vel[i];
////                                if (!vel_new.equals("")) {
////                                    String[] vel_new_lis = vel_new.split(",");
////                                    rve = new ReceiveVolEle();
////                                    for (int j = 0; j < vel_new_lis.length; j++) {
////                                        switch (j) {
////                                            case 1:
////                                                rve.setIndx(Integer.parseInt(vel_new_lis[j]));
////                                                rve.setCreateTime(DateUtils.parseDate());
////                                                rve.setGropId(simpleUUID);
////                                                Items items = findSelectItem();
////                                                rve.setItemId(items.getId());
////                                                break;
////                                            case 7:
////                                                rve.setTxv(vel_new_lis[j]);
////                                                break;
////                                            case 8:
////                                                rve.setTxc(vel_new_lis[j]);
////                                                break;
////
////                                            case 9:
////                                                rve.setRxv(vel_new_lis[j]);
////                                                break;
////                                        }
////
////                                    }
////                                    lis.add(rve);
////                                    queue1.enQueue(rve);
////                                    ReceiveVolEle rveDo = (ReceiveVolEle) queue1.deQueue();
////                                    //queue.clear();
////                                    if (rve != null && rve.getIndx() != null) {
////                                        receiveVolEleService.save(rve);
////                                    }
////                                    receive_sta = true;
////                                    System.out.println("socketUtil_statu =============================" + socketUtils.socket.isConnected());
////                                }
////
////                            }
////                        }
////                    }).start();
//
//
//                    break;
//                case MSG_RECEIVE_TU_NEW_DATA:
//                    //byte[] data4 = pyobj1.callAttr("onKConfirmToMcu", rec_count_s).toJava(byte[].class);
//                    //sendByte(data4);
//                    break;
//                case MSG_RECEIVE_POP_DATA:
//                    Boolean bool = showPopupWindow();
////                    byte[] data6 = pyobj1.callAttr("onKConfirmToMcu",rec_count).toJava(byte[].class);
////                    sendByte(data6);
//                    break;
//                default:
//                    break;
//            }
//        }
//
//        ;
//    };
//
//    private void savebitmap(Bitmap bitmap, String name) {
//
//        //创建文件，因为不存在2级目录，所以不用判断exist，要保存png，这里后缀就是png，要保存jpg，后缀就用jpg
//        File file = new File(ContextVariable.DOWN_NAME + "/img/" + fileName + "_" + name + ".png");
//        File downloadFile = new File(ContextVariable.IMG_DOWN_NAME);
//        try {
//            if (!downloadFile.exists()) {
//                downloadFile.mkdir();
//            }
//            //文件输出流
//            FileOutputStream fileOutputStream = new FileOutputStream(file);
//            //压缩图片，如果要保存png，就用Bitmap.CompressFormat.PNG，要保存jpg就用Bitmap.CompressFormat.JPEG,质量是100%，表示不压缩
//            bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
//            //写入，这里会卡顿，因为图片较大
//            fileOutputStream.flush();
//            //记得要关闭写入流
//            fileOutputStream.close();
//            //成功的提示，写入成功后，请在对应目录中找保存的图片
//            //System.out.println("写入成功！目录" + Environment.getExternalStorageDirectory() + "/"+name+".png");
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//            //失败的提示
//            System.out.println("写入失败！目录" + Environment.getExternalStorageDirectory() + "/" + name + ".png");
//        } catch (IOException e) {
//            e.printStackTrace();
//            //失败的提示
//            System.out.println("写入失败！目录" + Environment.getExternalStorageDirectory() + "/" + name + ".png");
//        }
//
//    }
//
//    /**
//     * 定义文件保存的方法，写入到文件中，所以是输出流
//     */
//    public void saveFile(String[] vel, String simpleUUID) {
//
//        String content = "";
//        FileOutputStream fos = null;
//        try {
//            // Context.MODE_PRIVATE私有权限，Context.MODE_APPEND追加写入到已有内容的后面
//            fos = myContext.openFileOutput(getFileName(simpleUUID), Context.MODE_APPEND);
//            String content1 = vel[0];
//            if (!content1.equals("") && content1.length() > 0) {//cvs头
//                fos.write(content1.getBytes());
//            }
//
//            for (int i = vel.length - 1; i >= 0; i--) {//cvs数据
//                if (i > 0) {
//                    if (!vel[i].contains("\n")) {
//                        content = vel[i];
//                    } else {
//                        content = vel[i].substring(1);
//                    }
//                    fos.write(content.getBytes());
//                    fos.write("\r\n".getBytes());//写入换行
//                }
//            }
//
//        } catch (IOException e) {
//            e.printStackTrace();
//        } finally {
//            if (fos != null) {
//                try {
//                    fos.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//    }
//
//    /**
//     * get file name such as 20171031.txt
//     *
//     * @return
//     */
//    private String getFileName(String simpleUUID) {
//        Items items = findSelectItem();
//        return items.getId() + "-" + simpleUUID + ".cvs";
//    }
//
////    private void savebitmap(Bitmap bitmap) {
////
////        //创建文件，因为不存在2级目录，所以不用判断exist，要保存png，这里后缀就是png，要保存jpg，后缀就用jpg
////        File file = new File(Environment.getExternalStorageDirectory() + "/mfw.png");
////        try {
////            //文件输出流
////            FileOutputStream fileOutputStream = new FileOutputStream(file);
////            //压缩图片，如果要保存png，就用Bitmap.CompressFormat.PNG，要保存jpg就用Bitmap.CompressFormat.JPEG,质量是100%，表示不压缩
////            bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
////            //写入，这里会卡顿，因为图片较大
////            fileOutputStream.flush();
////            //记得要关闭写入流
////            fileOutputStream.close();
////            //成功的提示，写入成功后，请在对应目录中找保存的图片
////            System.out.println("写入成功！目录" + Environment.getExternalStorageDirectory() + "/mfw.png");
////        } catch (FileNotFoundException e) {
////            e.printStackTrace();
////            //失败的提示
////            System.out.println("写入失败！目录" + Environment.getExternalStorageDirectory() + "/mfw.png");
////        } catch (IOException e) {
////            e.printStackTrace();
////            //失败的提示
////            System.out.println("写入失败！目录" + Environment.getExternalStorageDirectory() + "/mfw.png");
////        }
////
////    }
//
//
//    @Override
//    protected void onDestroy() {
//        super.onDestroy();
//        //退出HandlerThread的Looper循环。
//        System.out.println("---------------------- onDestroy --------------------");
//        SocketUtils.success_count = 0;
//        //socketUtils.buffer = null;
//        socketUtils.releaseSocket();
//        msg_sueecss_count = 0;
//        startGater = false;
//
//    }
//
//    public int getBoxInx() {
//        Items items = findSelectItem();
//        itemsId = items.getId().toString();
//        Arrange arrange1 = new Arrange();
//        arrange1.setItemId(Integer.valueOf(itemsId));
//        List<Arrange> arrangeLis = arrangeService.getArrange(arrange1);
//        abmnLen = arrangeLis.get(0).deviceTypeLen + 1;
//        Device device = new Device();
//        device.setItemId(itemsId);
//        List<Device> lis = deviceService.getDevice(device);
//        int count = 0;
//        if (lis.size() == 0) {
//            Toast.makeText(myContext, "网络连接失败！", Toast.LENGTH_SHORT).show();
//            //return;
//            count = 0;
//        } else if (lis.size() > 0) {
//            String box = lis.get(0).getBox().replaceAll(" ", "");
//            String[] boxlis = box.split(",");
//            alis = new ArrayList();
//            for (int i = 0; i < boxlis.length; i++) {
//                if (!boxlis[i].equals("0")) {
//                    alis.add(boxlis[i]);
//                }
//            }
//            count = abmnLen / alis.size();
//        }
//
//        return count;
//    }
//
//
//    private synchronized Boolean recv_float_array_with_indx(String[] abmnlis) throws InterruptedException, IOException {
////        Timer timer = new Timer();
////        TimerTask task = new TimerTask() {
////            @Override
////            public void run() {
////                SocketUtils.success_count = 6;
////                byte[] data4 = pyobj1.callAttr("onKConfirmToMcu", SocketUtils.packet_indx).toJava(byte[].class);
////                SocketUtils.writeMsgByte(data4);
////                System.out.println(" 超时重复开始= " + DateUtils.parseYmdHmsDate());
////            }
////        };
//        int status = 0;
//        int error = 0;
//        int rec_count = 0;
//        int bak_packet_lens = 0;
//        int bak_indx = 0;
//        returnSta = false;
//        recv_float_bool = true;
//
//        while (recv_float_bool) {
//            //if (queue != null) {
//            //Log.i("buffer","-------------success_count = "+SocketUtils.success_count );
//            if (socketUtils.success8) {
//                if (SocketUtils.success_count > 7) {
//                    bak_packet_lens = SocketUtils.packet_lens_old / 3;
//                    error = 0;
//                    if (!errorSta) {
//                        //接收包头AA55
//                        receive_one_field_sta = true;
//                        Map<String, Object> map = receive_one_field1("AA55");
//                        receive_one_field_sta = false;
//                        List<Byte> ab = dataParseUtil.objToByList(map.get("one_field"));
//
//                        byte[] str_one_field = dataParseUtil.listTobytes(ab);
//                        //System.out.println("str_one_field head ===" + str_one_field);
//                        int str_one_field_len = str_one_field.length;
//                        Boolean timeout = (Boolean) map.get("timeout");
////                if(receive_packet_indx_count == 1){
////                    System.out.println("--------------------head-str_one_field--------------------" + map.get("one_field").toString());
////                }
//                        //String str = abmnlis[0]+abmnlis[1]+abmnlis[2]+abmnlis[3];
//                        // if(str.equals("1245")){
////                    if(errorCount){
////                        error=1;
////                        errorCount = false;
////                        //break;
////                    }
//                        //}
//
//
//                        if (timeout) {
//                            error = error + 1;
//                            //break;
//                        }
//
//                        if (str_one_field_len > 0) {
//                            //System.out.println("--------------------str_one_field000--------------------");
//
//                            // System.out.println("--------------------str_one_field111--------------------");
//                            //int str_lens = dataParseUtil.entiretyDecodeStructByteBack(str_one_field);
//                            if (str_one_field[0] == 0) {
//                                System.out.println("header len error 0" + str_one_field);
//                                //continue;
//                                error += 1;
//                                boolErr = true;
//
//                            } else if (str_one_field_len < 2) {
//                                System.out.println("header len error 1" + str_one_field);
//                                //System.out.println("last indx= " + bak_indx);
//                                //continue;
//                                error += 1;
//                                boolErr = true;
//
//                            } else if (str_one_field_len > 2) {
//                                error = error + 1;
//                                boolErr = true;
//                                System.out.println("header len >4, break: " + str_one_field);
//                                //break;
//
//                            } else {
//                                int header = recv_unsigned_int(str_one_field);
//                                // vol_ele += ContextVariable.freq + ",";
//                                //vol_ele += packet_indx + ",";
//                                //System.out.println("00000000000000000000 header= " + header);
//                                queueMsg.enQueue(ContextVariable.freq + ",");
//                                queueMsg.enQueue(SocketUtils.packet_indx + ",");
//                                if (header != 0xAA55) {
//                                    boolErr = true;
//                                    System.out.println("header error " + new String(str_one_field));
//                                    //continue;
//
//                                }
//                            }
//                        }
//                    }
//                    //接收包的indx
//                    //需要对接收到的_receive_one_field的长度做判断，如果长度不够，就认为接收出错
//                    receive_one_field_sta = true;
//                    Map<String, Object> map2 = receive_one_field1("indx");
//                    receive_one_field_sta = false;
//                    List<Byte> ab2 = dataParseUtil.objToByList(map2.get("one_field"));
//                    byte[] str_one_field2 = dataParseUtil.listTobytes(ab2);
//                    int str_one_field2_len = str_one_field2.length;
//                    Boolean timeout2 = (Boolean) map2.get("timeout");
//                    //System.out.println("--------------------str_one_field2--------------------" + str_one_field2);
//                    if (timeout2) {
//                        error = error + 1;
//                        boolErr = true;
//                        // break;
//                        System.out.println("接收包的indx error0 " + new String(str_one_field2));
//
//                    }
//                    int indx = 0;
//                    if (str_one_field2_len > 0) {
//                        //int str_lens = dataParseUtil.entiretyDecodeStructByteBack(str_one_field2);
//                        if (str_one_field2_len != 2) {
//                            error = error + 1;
//                            //System.out.println("接收包的indx error1 " + new String(str_one_field2));
//
//                        } else {
//                            indx = recv_unsigned_int(str_one_field2);
//                            if (indx == 43605) {
//                                //System.out.println("接收包的indx 出错  " + indx);
//                            }
//                            if (errorSta) {
//                                //System.out.println("接收包的indx 出错  " + indx);
//                            } else {
//                                //System.out.println("接收包的indx正常-----------  " + indx);
//                            }
//                            errorSta = false;
//                            queueMsg.enQueue(indx + ",");
//                            queueMsg.enQueue(abmnlis[0] + ",");
//                            queueMsg.enQueue(abmnlis[1] + ",");
//                            queueMsg.enQueue(abmnlis[2] + ",");
//                            queueMsg.enQueue(abmnlis[3] + ",");
//                            if (indx > bak_packet_lens) {
//                                error = error + 1;
//                                boolErr = true;
//                                //break;
//                                System.out.println("接收包的indx 出错  " + indx);
//
//                            }
//
//                        }
//                    }
//
//                    //tx_voltage_data
//
//                    receive_one_field_sta = true;
//                    Map<String, Object> map3 = receive_one_field1("tx_voltage_data");
//                    receive_one_field_sta = false;
//                    List<Byte> ab3 = dataParseUtil.objToByList(map3.get("one_field"));
//                    byte[] str_one_field3 = dataParseUtil.listTobytes(ab3);
//                    int str_one_field3_len = str_one_field3.length;
//
//                    Boolean timeout3 = (Boolean) map3.get("timeout");
//                    //System.out.println("--------------------str_one_field3--------------------" + str_one_field3);
//                    if (timeout3) {
//                        error = error + 1;
//                        boolErr = true;
//                        //break;
//                        System.out.println("tx_voltage_data timeout3 error " + new String(str_one_field3));
//
//                    }
//                    String tx_voltage1 = null;
//                    if (str_one_field3_len > 0) {
//                        // int str_lens = dataParseUtil.entiretyDecodeStructByteBack(str_one_field3);
//                        if (str_one_field3_len != 4) {
//                            error = error + 1;
//                            boolErr = true;
//                            //break;
//                            System.out.println("tx_voltage_data error1 " + new String(str_one_field3));
//
//                        } else {
//                            tx_voltage1 = recv_float(str_one_field3);
//                            queueMsg.enQueue(tx_voltage1 + ",");
//                        }
//                    }
//
//                    //tx_current_data
//
//                    receive_one_field_sta = true;
//                    Map<String, Object> map4 = receive_one_field1("tx_current_data");
//                    receive_one_field_sta = false;
//                    List<Byte> ab4 = dataParseUtil.objToByList(map4.get("one_field"));
//                    byte[] str_one_field4 = dataParseUtil.listTobytes(ab4);
//                    int str_one_field4_len = str_one_field4.length;
//                    Boolean timeout4 = (Boolean) map4.get("timeout");
//                    //System.out.println("--------------------str_one_field4--------------------" + str_one_field4);
//                    if (timeout4) {
//                        error = error + 1;
//                        boolErr = true;
//                        //break;
//                        System.out.println("tx_current_data timeout4 error" + new String(str_one_field4));
//                    }
//                    String tx_current1 = null;
//                    if (str_one_field4_len > 0) {
//                        //int str_lens = dataParseUtil.entiretyDecodeStructByteBack(str_one_field4);
//                        if (str_one_field4_len != 4) {
//                            error = error + 1;
//                            boolErr = true;
//                            //break;
//                            System.out.println("tx_current_data error1 " + new String(str_one_field4));
//
//                        } else {
//                            tx_current1 = recv_float(str_one_field4);
//                            queueMsg.enQueue(tx_current1 + ",");
//                        }
//                    }
//
//                    //rx_voltage_data
//
//                    int indx_end = 0;
//                    receive_one_field_sta = true;
//
//                    Map<String, Object> map5 = receive_one_field1("rx_voltage_data");
//                    //System.out.println(indx);
//                    receive_one_field_sta = false;
//                    List<Byte> ab5 = dataParseUtil.objToByList(map5.get("one_field"));
////                byte[] str_one_field5 = dataParseUtil.listTobytes(ab5);
//                    byte[] str_one_field5 = dataParseUtil.listTobytes(ab5);
//                    int str_one_field5_len = str_one_field5.length;
//                    Boolean timeout5 = (Boolean) map5.get("timeout");
//                    //System.out.println("--------------------str_one_field5--------------------" + str_one_field5);
//
//                    if (timeout5) {
//                        error = error + 1;
//                        boolErr = true;
//                        //break;
//                        System.out.println("rx_voltage_data error " + new String(str_one_field5));
//
//                    }
//                    String rx_voltage1 = null;
//
//                    if (str_one_field5_len > 0) {
//                        if (str_one_field5_len != 4) {
//                            error = error + 1;
//                            boolErr = true;
//                            //break;
//                            System.out.println("rx_voltage_data error1 " + new String(str_one_field5));
//
//                        } else {
////                            long startTime = System.currentTimeMillis(); //起始时间
//                            rx_voltage1 = recv_float(str_one_field5);
//                            queueMsg.enQueue(rx_voltage1 + ";");
//                            rx_voltage_data1.append(rx_voltage1 + ",");
////                            long endTime = System.currentTimeMillis(); //结束时间
////                            long runTime = endTime - startTime;
////                            Log.i("test", String.format("方法使用时间 %d ms", runTime));
//                        }
//                    }
//                    //System.out.println(" -----index = " + indx);
//
//                    if (error == 0) {
//                        rec_count = rec_count + 1;
//                        //rx_voltage_data += rx_voltage1 + ",";
//
//                        SocketUtils.packet_lens -= 3;
//                        //System.out.println("SocketUtils.packet_lens ------------- " + SocketUtils.packet_lens + " -----index = " + indx);
//                        if (SocketUtils.packet_lens <= 0) {
//
//                            if (bak_packet_lens == rec_count) {
//                                // System.out.println(" =============== 4,start; 结束= " + DateUtils.parseYmdHmsDate());
//                                //System.out.println(rx_voltage_data);
//                                recv_float_bool = false;
//                                receive_one_field_sta = false;
//
//                                SocketUtils.resumeThread();
//                                SocketUtils.success_count = 6;
//
//                                anewSta = true;
//                                byte[] data4 = pyobj1.callAttr("onKConfirmToMcu", rec_count).toJava(byte[].class);
//                                SocketUtils.writeMsgByte(data4);
//                                anewSta = true;
//                                System.out.println(" 重复开始= " + DateUtils.parseYmdHmsDate());
//                                System.out.println("------------ bytecount ==============" + socketUtils.bytecount);
//                                socketUtils.bytecount = 0;
//                                rx_voltage_data1 = new StringBuffer();
////                            Timer timer1 = new Timer();
////                            TimerTask task = new TimerTask() {
////                                @Override
////                                public void run() {
////                                    getTask();
////                                }
////                            };
////                            timer1.schedule(task,0,timeouts);
////                            timer1.cancel();
//                                new Thread(new Runnable() {
//                                    @Override
//                                    public void run() {
//                                        saveCvs();
//                                    }
//                                }).start();
//
//                                recv_float_bool = true;
//                                receive_one_field_sta = true;
//
//                                //System.out.println(" 点击结束= " + DateUtils.parseYmdHmsDate());
//                                SocketUtils.packet_indx -= 1;
//                                rec_count_s = rec_count;
//                                rec_count = 0;
//                                back_over = true;
//                                receive_packet_indx_count += 1;
//                                rx_voltage_data_all1.append(rx_voltage_data1.toString() + ";");
//                                if (SocketUtils.packet_indx == 0) {
//                                    //String[] rxStrList = rx_voltage_data_all.split(";");
//                                    String[] rxStrList = rx_voltage_data_all1.toString().split(";");
//                                    String rx_voltage_data_add = ArrayUtil.strToStrArrrayAdd(rxStrList);
//                                    rx_voltage_data_len = rx_voltage_data_add.substring(0, rx_voltage_data_add.length() - 1).split(",").length;
//                                    if (!rx_voltage_data_add.equals("")) {
//                                        Message msg = new Message();
//                                        msg.what = MSG_RECEIVE_TU_DATA;
//                                        msg.obj = rx_voltage_data_add;
//                                        mHandler.sendMessage(msg);
//                                    }
//                                    rx_voltage_data1 = new StringBuffer();
//                                    rx_voltage_data_all1 = new StringBuffer();
//                                    returnSta = true;
//                                    System.out.println("---------------------重复开始 break------------");
//                                    break;
//                                }
//                                //返回正确确认包，
//                                status = 0;
//
//                            } else {
////                        byte[] data4 = pyobj1.callAttr("onKConfirmToMcu", 0).toJava(byte[].class);
////                        SocketUtils.writeMsgByte(data4);
//                                status = 1;
//                            }
//                        } else if (SocketUtils.packet_lens > 0 && indx == 1) {//数据丢包处理，index =1 重新发送命令
//                            Thread.sleep(1000);
//                            System.out.println("------------ bytecount error ==============" + socketUtils.bytecount +"--"+ SocketUtils.packet_lens +"--"+ indx);
//                            socketUtils.bytecount = 0;
//                            rx_voltage_data1 = new StringBuffer();
//                            rx_voltage_data_all1 = new StringBuffer();
//                            errorSta = false;
//                            errorCount = false;
//                            anewSta = false;
//                            error = 0;
//                            returnSta = false;
//                            SocketUtils.resumeThread();
//                            SocketUtils.success_count = 5;
//
//                            SocketUtils.packet_lens = SocketUtils.packet_lens_old;
//                            //SocketUtils.packet_lens=0;
//
//                            Thread.sleep(10);
//                            byte[] data4 = pyobj1.callAttr("onKReSync", SocketUtils.packet_indx).toJava(byte[].class);
//                            SocketUtils.writeMsgByte(data4);
//                            System.out.println(" 数据丢包，重复开始= " + DateUtils.parseYmdHmsDate());
//                        }
//                    } else {
//                        Boolean bl1 = false;
//                        Boolean bl2 = false;
//                        while (boolErr) {
//                            receive_one_field_sta = false;
//                            byte tmp = socketUtils.read();
//
//                            //System.out.println("tmp ===" + tmp);
//                            if (String.valueOf(tmp).equals("85")) {
//                                //System.out.println("tmp ===" + tmp);
//                                bl1 = true;
//                                continue;
//                            }
//                            if (bl1) {
//                                if (String.valueOf(tmp).equals("-86")) {
//                                    //System.out.println("tmp2 ===" + tmp);
//                                    bl2 = true;
//                                    bl1 = false;
//                                    continue;
//                                }
//                            }
//                            if (bl2) {
//                                //System.out.println("tmp3 ===" + tmp);
//                                errorSta = true;
//                                rec_count = rec_count + 1;
//                                SocketUtils.packet_lens -= 3;
//                                boolErr = false;
//                                bl2 = false;
//                                receive_one_field_sta = true;
//                                break;
//
//                            }
//                        }
//                        continue;
//                    }
////                    if (error > 0){
////                        rx_voltage_data1 = new StringBuffer();
////                        rx_voltage_data_all1 = new StringBuffer();
////                        SocketUtils.success_count = 8;
////                        errorCount = false;
////                        anewSta = false;
////                        System.out.println("=================error > 0================");
////                        bool = false;
////
////                        SocketUtils.success_count = 8;
////                        SocketUtils.resumeThread();
////                        error = 0;
////                        returnSta = false;
////                        Boolean bool1=true;
////                        rec_count = 0;
////                        while (bool1){
////                            if(!socketUtils.success8){
////
////                                System.out.println("---------------------错误结束-----------------");
////                                Thread.sleep(1000);
////                                byte[] data5 = pyobj1.callAttr("onKReSync", SocketUtils.packet_indx).toJava(byte[].class);
////                                SocketUtils.writeMsgByte(data5);
////                                bool1 = false;
////                                socketUtils.success8 = true;
//////                                Timer timer = new Timer();
//////                                TimerTask task = new TimerTask() {
//////                                    @Override
//////                                    public void run() {
//////                                        getTask();
//////                                    }
//////                                };
//////                                timer.schedule(task,0,timeouts);
//////                                timer.cancel();
////                                break;
////                            }else {
////                               // System.out.println("---------------------错误运行中-----------------");
////                            }
////                        }
////                    }
//                }
//                //}
//            }
//
//        }
////        if (error > 0) {
////            errorCount = false;
////            anewSta = false;
////
////            System.out.println("=================error > 0================");
////            bool = false;
////            SocketUtils.success_count = 8;
////
////            status = 1;
//////            SocketUtils.pauseThread();
//////            socketUtils.readClear(1);
////            SocketUtils.resumeThread();
////
////            //recv_float_bool = false;
////
////            Thread.sleep(1000);
////            //socketUtils.readClear(0);
////            System.out.println("=================error > 11111111111111111================");
////            error = 0;
////
////
////            //Thread.sleep(5000);
//////            recv_float_bool = false;
//////            recv_float_bool2 = false;
////            //myThread.pauseThread();
//////            Thread.sleep(4000);
////           // myThread.resumeThread();
//////            recv_float_bool = true;
//////            recv_float_bool2 = true;
////            //while (!socketUtils.success8){
////                returnSta = false;
////                socketUtils.success8 = true;
////                byte[] data5 = pyobj1.callAttr("onKReSync", SocketUtils.packet_indx).toJava(byte[].class);
////                SocketUtils.writeMsgByte(data5);
////            SocketUtils.success_count = 5;
////                //Thread.sleep(4000);
////            //}
////
////            //return returnSta;
////        }
//        return returnSta;
//    }
//
//    private Map<String, Object> receive_one_field(String name) throws InterruptedException {
//        Map<String, Object> map = new HashMap<>();
//        Boolean escaped = false;
//        Boolean command_sep_found = false;
//        ArrayList<Byte> one_field = new ArrayList<Byte>();
//        Boolean timeout = false;
//
//        while (receive_one_field_sta) {
////            Thread.sleep(0);
//            if (queue.QueueEmpty()) {
//                //System.out.println("queue 是空队列 = " + queue.QueueEmpty()+" ----  mTheead ="+mReceiveThread.getState());
//            } else {
//                //Log.i("队列", "9999999999999999999999------- queue=" + queue.QueueEmpty());
//                if (queue.QueueLength() > 0) {
//                    if (queue.QueueLength() == 0) {
//                        break;
//                    }
//
//                    byte tmp = (byte) queue.deQueue();
//
////                    System.out.println("9999999999999999999999------- tmp=" + tmp);
//                    // System.out.println("9999999999999999999999------- name=" + name);
//                    //System.out.println("queue 不是空 = " + queue.QueueEmpty()+" ----  mTheead ="+mReceiveThread.getState());
//
//
//                    if (escaped) {
//                        if (tmp == 44 || tmp == 59 || tmp == 47) {
//                            one_field.add(tmp);
//                            escaped = false;
//                        } else {
//                            one_field.add(tmp);
//                            escaped = false;
//                        }
//                    } else {
//                        if (tmp == 47) {
//                            //遇到 / 就escaped = True 继续循环
//                            escaped = true;
//                        } else if (tmp == 44) {
//                            break;
//                        } else if (tmp == 59) {
//                            command_sep_found = true;
//                            break;
//                        } else {
//                            one_field.add(tmp);
//                        }
//                    }
//                }
//            }
//        }
//        map.put("one_field", one_field);
//        map.put("timeout", timeout);
//        return map;
//    }
//
//    // 从byte数组的index处的连续4个字节获得一个float
//    public static float getFloats(byte[] arr, int index) {
//        return Float.intBitsToFloat(getInts(arr, index));
//    }
//
//    // 从byte数组的index处的连续4个字节获得一个int
//    public static int getInts(byte[] arr, int index) {
//        return (0xff000000 & (arr[index + 0] << 24)) |
//                (0x00ff0000 & (arr[index + 1] << 16)) |
//                (0x0000ff00 & (arr[index + 2] << 8)) |
//                (0x000000ff & arr[index + 3]);
//    }
//
//    public synchronized void saveCvs() {
//        int len = queueMsg.QueueLength() / 10;
//        String[] vel = new String[len];
//        String[] velLisnew = new String[len];
//        //int ii = 0;
//        for (int i = 0; i < len; i++) {
//            //ii+=1;
//            StringBuffer val = new StringBuffer();
//            for (int j = 0; j < 10; j++) {
//                val.append(queueMsg.deQueue().toString());
//
//            }
//
//            vel[i] = val.toString().replace(";", "");
////            String[] velLis = vel[i].toString().split(",");
////            for (int j = 0; j < velLis.length; j++) {
////                if(j==3 || j==4 || j==5 || j==6){
////                    velLis[j] = boxLatLon.get(Integer.parseInt(velLis[j]) - 1);
////                }
////            }
////            String velStr = String.join(",", velLis);
////            velLisnew[i] = velStr+"\n";
//        }
//
//        Integer cvs_line_count = FileDownUtil.saveFileNew(myContext, vel, fileName + ".cvs", cvs_line);
//        cvs_line = cvs_line_count;
//
//        //String[] vel =queueMsg.toArray();
//        //String[] vel = vol_ele.split(";");
//        //生成的是不带-的字符串，类似于：b17f24ff026d40949c85a24f4f375d42
////        String simpleUUID = IdUtil.simpleUUID();
////        String fileName = FileDownUtil.getFileName(simpleUUID);
//        //FileDownUtil.saveFile(myContext, vel, simpleUUID);
//
////        List<ReceiveVolEle> lis = new ArrayList<ReceiveVolEle>();
////        ReceiveVolEle rve = null;
////        MyQueue queue1 = new MyQueue();
////        int ii = 0;
////        if (!receive_sta) {
////            ii = 1;
////        }
////        for (int i = ii; i < vel.length; i++) {
////            String vel_new = "";
//////                        if (i != 0) {
//////                            vel_new = vel[i].substring(1, vel[i].length());
//////                        } else {
////
////
////            vel_new = vel[i];
////            //}
////            if (!vel_new.equals("")) {
////                String[] vel_new_lis = vel_new.split(",");
////                rve = new ReceiveVolEle();
////                for (int j = 0; j < vel_new_lis.length; j++) {
////                    switch (j) {
////                        case 1:
////                            rve.setIndx(Integer.parseInt(vel_new_lis[j]));
////                            rve.setCreateTime(DateUtils.parseDate());
////                            rve.setGropId(simpleUUID);
////                            Items items = findSelectItem();
////                            rve.setItemId(items.getId());
////                            break;
////
////                        case 7:
////                            rve.setTxv(vel_new_lis[j]);
////                            break;
////                        case 8:
////                            rve.setTxc(vel_new_lis[j]);
////                            break;
////
////                        case 9:
////                            rve.setRxv(vel_new_lis[j]);
////                            break;
////                    }
////
////                }
////                lis.add(rve);
////                queue1.enQueue(rve);
////                ReceiveVolEle rveDo = (ReceiveVolEle) queue1.deQueue();
////                //queue.clear();
////                if (rve != null && rve.getIndx() != null) {
////                    receiveVolEleService.save(rve);
////                }
////                receive_sta = true;
////            }
////
////        }
//    }
//
//    private synchronized Map<String, Object> receive_one_field1(String name) throws InterruptedException {
//        Map<String, Object> map = new HashMap<>();
//        Boolean escaped = false;
//        Boolean command_sep_found = false;
//        ArrayList<Byte> one_field = new ArrayList<Byte>();
//        Boolean timeout = false;
//
//        while (receive_one_field_sta) {
//            byte tmp = socketUtils.read();
//            //System.out.println("9999999999999999999999------- tmp=" + tmp);
////            if(tmp == 0){
////                continue;
////            }
//            //System.out.println("9999999999999999999999------- tmp=" + tmp);
//            // System.out.println("9999999999999999999999------- name=" + name);
//            //System.out.println("queue 不是空 = " + queue.QueueEmpty()+" ----  mTheead ="+mReceiveThread.getState());
//
//            if (escaped) {
//                if (tmp == 44 || tmp == 59 || tmp == 47) {
//                    one_field.add(tmp);
//                    escaped = false;
////                    if(tmp == 59){
////                        socketUtils.count59 += 1;
////                    }
//                } else {
//                    one_field.add(tmp);
//                    escaped = false;
//                }
//            } else {
//                if (tmp == 47) {
//                    //遇到 / 就escaped = True 继续循环
//                    escaped = true;
//                } else if (tmp == 44) {
//                    break;
//                } else if (tmp == 59) {
//                    command_sep_found = true;
//                    break;
//                } else {
//                    one_field.add(tmp);
//                }
//            }
//            //tmp = Byte.parseByte(null);
//        }
////        if(name.equals("AA55")){
////            System.out.println("  ------ AA55 ---"+one_field);
////        }
//        map.put("one_field", one_field);
//        map.put("timeout", timeout);
//
//        return map;
//    }
//
//    private Integer recv_unsigned_int(byte[] val) {
//
//        return DataParseUtil.recv_unsigned_int(val);
//    }
//
//    private String recv_float(byte[] val) {
//        return DataParseUtil.recv_float(val);
//    }
//
//
//    @SuppressLint("MissingInflatedId")
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        if (android.os.Build.VERSION.SDK_INT > 9) {
//            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
//            StrictMode.setThreadPolicy(policy);
//        }
//        dataParseUtil = new DataParseUtil();
//        dbHelper = new DatabaseHelper(this);
//        initService();
//
////
////        socketUtils = new SocketUtils();
////        try {
////            Thread.sleep(100);
////            socketUtils.releaseSocket();
////        } catch (InterruptedException e) {
////            throw new RuntimeException(e);
////        }
////        socketUtils = null;
////        SocketUtils.success_count =0;
////        SocketUtils.receiveDataAll = "";
//
//
//        //socketUtils = SocketUtils.getInstance();
//        //socketUtils.releaseSocket();
//
//
//        setContentView(R.layout.send_receive_add);
//        arrangeService = new ArrangeService();
//        myContext = this;
////        new Thread(new Runnable() {
////            @Override
////            public void run() {
//        socketUtils = SocketUtils.getInstance(myContext);
//        if (socketUtils.socket == null) {
//            Toast.makeText(myContext, "网络连接失败！", Toast.LENGTH_SHORT).show();
//            SendReceiveAddBackNewActivity.this.finish();
//        }
//        myThread = new MyThread();
//        SocketUtils.success_count = 0;
//        SocketUtils.receiveDataAll = "";
//        socketListener();
//
////            }
////        }).start();
//        deviceDao = new DeviceDao();
//        all_byte_lis = new ArrayList<byte[]>();
//        stringBufferData = new StringBuffer();
//        title_back = findViewById(R.id.title_back);
//        title_text = findViewById(R.id.title_text);
//        title_seting = findViewById(R.id.title_setting);
//        title_text.setText("发射接收信息");
//        title_seting.setVisibility(View.INVISIBLE);
//        receive_voltage = findViewById(R.id.receive_voltage_val);
//
//        send_sub_btn = findViewById(R.id.send_sub_btn);
//        receiveService = new ReceiveService();
//        deviceService = new DeviceService();
//        itemsService = new ItemsService();
//        listitem = new ArrayList<Map<String, Object>>();
//        SharedPreferences sp = this.getSharedPreferences(this.getPackageName(), Activity.MODE_PRIVATE);
//        String ips = sp.getString("ip", "");
//        initTextView();
//        initData();
//        //HexBinary();
//        Resources res = getResources();
//        freqData = res.getStringArray(R.array.freqData);
//        queue = new MyQueue();
//        queueMsg = new MyQueue();
//        mSharedPreferences = getSharedPreferences("setting", Context.MODE_PRIVATE);
//
//        rx_voltage_data1 = new StringBuffer();
//        rx_voltage_data_all1 = new StringBuffer();
//        boxId = getBoxInx();
//        //获取保存的ip地址、客户端端口号
//        //mIpAddress = mSharedPreferences.getString(IP_ADDRESS, null);
//        //mClientPort = mSharedPreferences.getInt(CLIENT_PORT, DEFAULT_PORT);
//        title_back.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                SendReceiveAddBackNewActivity.this.finish();
//            }
//        });
//
//        send_sub_btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (send_voltage_val.length() > 0) {
////                    if (send_voltage_val.length() > 0 &&
////                            send_duration_val.length() > 0) {
//                    //System.out.println(" 点击开始= " + DateUtils.parseYmdHmsDate());
//                    try {
//                        getTexts();
//                    } catch (InterruptedException e) {
//                        throw new RuntimeException(e);
//                    }
//                    //ProgressDialogUtils.showProgressDialog(myContext,"采集中...");
//                } else {
//                    Toast.makeText(myContext, "发射信息不能为空！", Toast.LENGTH_SHORT).show();
//                }
//            }
//        });
//        Items items = findSelectItem();
//        itemsId = items.getId().toString();
//        alarmService = new AlarmService();
//        Alarm alarm = new Alarm(itemsId);
//        alarm.setAlarmMsg("err_message");
//        SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm");
//        Date date = new Date(System.currentTimeMillis());
//        alarm.setCreateTime(sim.format(date));
//        alarm.setUpdateTime(sim.format(date));
//        alarm.setStatus(0);
//        alarm.setItemId(itemsId);
//        alarmService.save(alarm);
//
//
//        try {
//            initPython(this);
//            //NetWorkUtil.getApIpAddress2();
//            //pyMain();
//        } catch (JSONException e) {
//            throw new RuntimeException(e);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
//    }
//
//
//    @Override
//    public void onBackPressed() {
//        super.onBackPressed();
//    }
//
//    private void initTextView() {
//        send_voltage_val = findViewById(R.id.send_voltage_val);
//        send_repeat_val = findViewById(R.id.send_repeat_val);
//        send_frequency_val = findViewById(R.id.send_frequency_val);
//        //send_duration_val = findViewById(R.id.send_duration_val);
//        //clear_all_mux_box_connect_val = findViewById(R.id.clear_all_mux_box_connect_val);
//    }
//
//    private void initService() {
//        boxOneService = new BoxOneService();
//        boxTwoService = new BoxTwoService();
//        boxThreeService = new BoxThreeService();
//        boxFourService = new BoxFourService();
//        boxFiveService = new BoxFiveService();
//        boxSixService = new BoxSixService();
//        boxSevenService = new BoxSevenService();
//        boxEightService = new BoxEightService();
//        boxNineService = new BoxNineService();
//        boxTenService = new BoxTenService();
//        Items items = findSelectItem();
//        itemsId = items.getId().toString();
//        //boxLatLon
//        List<String> lisBoxOne = performJoinQuery(itemsId, "tb_boxOne");
//        List<String> lisBoxTwo = performJoinQuery(itemsId, "tb_boxTwo");
//        List<String> lisBoxThree = performJoinQuery(itemsId, "tb_boxThree");
//        List<String> lisBoxFour = performJoinQuery(itemsId, "tb_boxFour");
//        List<String> lisBoxFive = performJoinQuery(itemsId, "tb_boxFive");
//        List<String> lisBoxSix = performJoinQuery(itemsId, "tb_boxSix");
//        List<String> lisBoxSeven = performJoinQuery(itemsId, "tb_boxSeven");
//        List<String> lisBoxEight = performJoinQuery(itemsId, "tb_boxEight");
//        List<String> lisBoxNine = performJoinQuery(itemsId, "tb_boxNine");
//        List<String> lisBoxTen = performJoinQuery(itemsId, "tb_boxTen");
//        if (lisBoxOne.size() > 0) {
//            boxLatLon = new ArrayList<>();
//            String[] str = lisBoxOne.toArray(new String[0]);
//            for (String item : str) {
//                boxLatLon.add(item);
//            }
//        }
//        System.out.println("------------");
//    }
//
//    private List<String> performJoinQuery(String itemId, String tabName) {
//        SQLiteDatabase db = dbHelper.getReadableDatabase();
//
//        // SQL语句：查询用户表和订单表，根据用户ID关联
//        Cursor cursor = db.rawQuery("select box_one_lat,box_two_lat,box_three_lat,box_four_lat,box_five_lat,box_six_lat,box_seven_lat,box_eight_lat,box_nine_lat,box_ten_lat,box_eleven_lat,box_twelve_lat" +
//                " from " + tabName + " where item_id = ? ", new String[]{itemId});
//        System.out.println(cursor.getCount());
//        List<String> lis = new ArrayList<>();
//        // 遍历结果集
//        while (cursor.moveToNext()) {
//            String box_one_lat = cursor.getString(0);
//            String box_two_lat = cursor.getString(1);
//            String box_three_lat = cursor.getString(2);
//            String box_four_lat = cursor.getString(3);
//            String box_five_lat = cursor.getString(4);
//            String box_six_lat = cursor.getString(5);
//            String box_seven_lat = cursor.getString(6);
//            String box_eight_lat = cursor.getString(7);
//            String box_nine_lat = cursor.getString(8);
//            String box_ten_lat = cursor.getString(9);
//            String box_eleven_lat = cursor.getString(10);
//            String box_twelve_lat = cursor.getString(11);
//            lis.add(box_one_lat);
//            lis.add(box_two_lat);
//            lis.add(box_three_lat);
//            lis.add(box_four_lat);
//            lis.add(box_five_lat);
//            lis.add(box_six_lat);
//            lis.add(box_seven_lat);
//            lis.add(box_eight_lat);
//            lis.add(box_nine_lat);
//            lis.add(box_ten_lat);
//            lis.add(box_eleven_lat);
//            lis.add(box_twelve_lat);
//
//            // 处理查询结果
//            // ...
//        }
//
//        cursor.close();
//        db.close();
//        return lis;
//    }
//
//    private void socketListener() {
//
//        if (socketUtils != null) {
//            // 启动监听
//            socketUtils.startListening();
//            // 设置消息监听器
//            socketUtils.setOnMessageReceivedListener(new SocketUtils.OnMessageReceivedListener() {
//                @Override
//                public void onMessageReceived(byte message) {
//                    runOnUiThread(new Runnable() {
//                        @Override
//                        public void run() {
//                            //System.out.println("======================== socketUtils ================" + socketUtils == null);
//
//                            // 在UI线程更新消息
//                            queue.enQueue(message);
//                        }
//                    });
//                }
//
//                @Override
//                public void onMessageReceivedString(String message) {
//                    runOnUiThread(new Runnable() {
//                        @Override
//                        public void run() {
//
//
//                            if (errorRepeat) {//出错重复
//                                System.out.println("-------------onMessageReceivedString-出错重复-------------");
////                                Timer timer = new Timer();
////                                TimerTask task = new TimerTask() {
////                                    @Override
////                                    public void run() {
////                                        getTask();
////                                        errorRepeat = false;
////                                    }
////                                };
////                                timer.schedule(task,0,timeouts);
////                                timer.cancel();
//                            }
//                            // System.out.println("======================== success or bad_param ================" + message);
//                            if (recv_float_bool == false && recv_float_bool2 == false) {
//                                //System.out.println("======================== myThread.resumeThread()================" );
//                                recv_float_bool = true;
//                                recv_float_bool2 = true;
//                                myThread.resumeThread();
//                            }
//                            if (message.equals("None")) {
//                                System.out.println(" usb/wifi connect error ");
//                                return;
//                            }
//                            if (message.contains("kErrorAlarm")) {//告警写入
//                                System.out.println(" kErrorAlarm================= " + message);
//                                Alarm alarm = new Alarm(itemsId);
//                                alarm.setAlarmMsg(message);
//                                alarmService.save(alarm);
//                                return;
//                            }
//                            if (message.equals("null")) {
//                                if (startCount == 1) {
//                                    Toast.makeText(myContext, "采集数据失败！", Toast.LENGTH_SHORT).show();
//                                }
//                                return;
//                            }
//                            if (message.contains("0,Success;") && !message.equals("")) {
//                                msg_sueecss_count += 1;
//                                switch (msg_sueecss_count) {
//                                    case 2: //kSetTxWaveWithParam 3
//                                        if (data != null) {
//                                            SocketUtils.writeMsgByte(data);
//                                        }
//                                        break;
//                                    case 3://kClearAllMuxBoxConnect 15
//                                        if (data != null) {
//                                            SocketUtils.writeMsgByte(data2);
//                                        }
//                                        break;
//                                    case 4://kSetMuxBoxConnect 2
//                                        if (data != null) {
//                                            SocketUtils.writeMsgByte(data3);
//                                        }
//                                        break;
//                                    case 5:
//                                        if (data != null) {
//                                            String data = "23,r;";
//                                            SocketUtils.writeMsgByte(data.getBytes());
//                                        }
//                                        break;
//                                    case 6:
//                                        if (data != null) {
//                                            String data1 = "4,start;";
//                                            SocketUtils.writeMsgByte(data1.getBytes());
//
//                                            System.out.println(" =============== 4,start; 开始= " + DateUtils.parseYmdHmsDate());
//                                            System.out.println(" =============== 4,start; 开始= " + socketUtils.success_count);
////                                            Timer timer = new Timer();
////                                            TimerTask task = new TimerTask() {
////                                                @Override
////                                                public void run() {
////                                                    getTask();
////                                                    //errorRepeat = true;
////                                                }
////                                            };
////                                            timer.schedule(task,timeouts);
////                                            timer.cancel();
//                                            startGater = true;
//                                            myThread.resumeThread();
//                                        }
//                                        break;
//                                }
//                            } else if (message.contains("Timeout")) {
//                                System.out.println(" kSetMuxBoxConnect switch box connect error ");
//                            } else if (message.equals("0,Bad_Param;")) {
//                                System.out.println("======================== bad_param ================" + message);
//                            }
//                        }
//                    });
//                }
//
//                @Override
//                public void onConnectionLost() {
//                    runOnUiThread(new Runnable() {
//                        @Override
//                        public void run() {
//                            // 处理连接中断的情况，例如显示提示或重新连接
//                            //handleConnectionLost();
//                            System.out.println(" socket 断开==================================");
//                        }
//                    });
//                }
//            });
//
//
//        }
//    }
//
//    public void getTask() {
//        SocketUtils.success_count = 6;
//        byte[] data5 = pyobj1.callAttr("onKReSync", SocketUtils.packet_indx).toJava(byte[].class);
//        SocketUtils.writeMsgByte(data5);
//        System.out.println(" 超时重复开始= " + DateUtils.parseYmdHmsDate());
//    }
//
//    private void getTexts() throws InterruptedException {
//
//        if (send_voltage_val.getText().length() == 0) {
//            Toast.makeText(myContext, "电压不能为空！", Toast.LENGTH_SHORT).show();
//            return;
//        }
//        if (send_repeat_val.getText().length() == 0) {
//            Toast.makeText(myContext, "重复次数不能为空！", Toast.LENGTH_SHORT).show();
//            return;
//        }
//
////        if (send_duration_val.getText().length() ==0){
////            Toast.makeText(myContext, "发射时长不能为空！", Toast.LENGTH_SHORT).show();
////            return;
////        }
//        if (clear_all_mux_box_connect_val.getText().length() == 0) {
//            Toast.makeText(myContext, "重置电极不能为空！", Toast.LENGTH_SHORT).show();
//            return;
//        }
//        startCount = 1;
//        if (socketUtils == null) {
//            socketUtils = SocketUtils.getInstance(myContext);
//            socketListener();
//        }
//        if (queue == null) {
//            queue = new MyQueue();
//        }
//        if (inclickGatherCount > 0) {
//            Thread.sleep(1000);
//        }
//        SocketUtils.success_count = 1;
////        myThread = new MyThread();
//
//        packet_indx1 = Integer.parseInt(String.valueOf(send_repeat_val.getText()));
//        packet_indx = packet_indx1;
//        Sends sends = new Sends();
//        sends.setVoltage(String.valueOf(send_voltage_val.getText()));
//        sends.setType(0);
//        sends.setStatus(0);
//        sends.setRepeatNum(String.valueOf(send_repeat_val.getText()));
//        sends.setSendFrequency(String.valueOf(send_frequency_val.getSelectedItemPosition()));
//        sf = String.valueOf(send_frequency_val.getSelectedItemPosition() + 1);
//        //sends.setSendDuration(String.valueOf(send_duration_val.getText()));
//
//        //Items items = findSelectItem();
//        //itemsId = items.getId().toString();
//        sends.setItemId(Integer.valueOf(itemsId));
//        SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm");
//        Date date = new Date(System.currentTimeMillis());
//        sends.setCreateTime(sim.format(date));
//        sends.setUpdateTime(sim.format(date));
//        simpleUUID = IdUtil.simpleUUID();
//        fileName = FileDownUtil.getFileName(simpleUUID);
//        sends.setUid(simpleUUID);
//        sendsService = new SendsService();
//        receiveVolEleService = new ReceiveVolEleService();
//        String clearStr = clear_all_mux_box_connect_val.getText().toString();
//        String[] clearStrLis = clearStr.split(",");
//        int cslen = clearStrLis.length;
//        int csnewlen = 10 - clearStrLis.length;
//        String[] clearStrLisNew = new String[csnewlen];
//        List<String> list = null;
//        if (clearStrLis.length > 0 && clearStrLis.length < 10) {
//
//            for (int i = 0; i < csnewlen; i++) {
//                clearStrLisNew[i] = String.valueOf(0);
//            }
//            list = new ArrayList(Arrays.asList(clearStrLis));
//            list.addAll(Arrays.asList(clearStrLisNew));
//        } else {
//            list = new ArrayList(Arrays.asList(clearStrLis));
//        }
//        String join2 = Joiner.on(",").join(list);
//        sends.setBoxaddr(join2);
//        Object[] c = list.toArray();
//        clearStrLisAll = Arrays.toString(c).replace("[", "").replace("]", "").split(",");
//        Arrange arrange1 = new Arrange();
//        arrange1.setItemId(Integer.valueOf(itemsId));
//        List<Arrange> arrangeLis = arrangeService.getArrange(arrange1);
//        Integer ns = 0;
//
//        if (arrangeLis.size() == 0) {
//            Toast.makeText(myContext, "请先添加排列设计！", Toast.LENGTH_SHORT).show();
//            return;
//        } else {
//            ns = arrangeLis.get(0).getDeviceTypeLen();
//            dtype = arrangeLis.get(0).getDtype();
//            dtypelen = arrangeLis.get(0).getDeviceTypeLen();
//            shape = arrangeLis.get(0).getShape();
//            abmn = arrangeLis.get(0).getDeviceTypeVal();
//            dtypelen0 = dtypelen;
//        }
//
//
//        int countItem = findItemCount();
//
//        if (countItem > 0) {
//            boolean bl = sendsService.save(sends);
//            if (bl) {
//                Toast.makeText(myContext, "保存成功！", Toast.LENGTH_SHORT).show();
//                SharedPreferences.Editor editor = mSharedPreferences.edit();
//                editor.putInt("header_count", 0);
//                editor.remove("header");// 初始化清空header
//                showPopupWindow();//pop弹框
//                if (inclickGatherCount == 0) {
//                    if (!myThread.getState().equals("RUNNABLE")) {
//                        myThread.start();
//                    }
//
//                } else {
//                    inclickGatherCount = 0;
//                    myThread.resumeThread();
//                    returnSta = true;
////                    SocketUtils.success_count = 0;
//                    String data = "22,M;";
//                    SocketUtils.writeMsgByte(data.getBytes());
//                    SocketUtils.success_count = 0;
//                    SocketUtils.writeMsgByte(data.getBytes());
//                }
//
//            }
//
//        } else {
//            Toast.makeText(myContext, "请先创建项目！", Toast.LENGTH_SHORT).show();
//
//        }
//
//    }
//
//    class MyThread extends Thread {
//        public final Object lock = new Object();
//        public boolean threadExit;
//
//
//        public MyThread() {
//            threadExit = false;
//        }
//
//        /**
//         * 调用这个方法实现暂停线程
//         */
//        public void pauseThread() {
//            threadExit = true;
//        }
//
//        /**
//         * 调用这个方法实现恢复线程的运行
//         */
//        public void resumeThread() {
//            threadExit = false;
//            synchronized (lock) {
//                lock.notifyAll();
//            }
//        }
//
//        public void threadExit() {
//            threadExit = true;
//        }
//
//        /**
//         * 注意：这个方法只能在run方法里调用，不然会阻塞主线程，导致页面无响应
//         */
//        public void onPause() {
//            synchronized (lock) {
//                try {
//                    lock.wait();
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//
//        @Override
//        public void run() {
//            System.out.println("---------------dtypelen---" + dtypelen);
//            System.out.println("---------------threadExit---" + threadExit);
//            while (!threadExit) {
//                msg_sueecss_count = 2;
//                //returnSta = false;
//                String abmnStr = "";
//                if (inclickGatherCount == 0) {
//                    System.out.println("---------------dtypelen2---" + 0);
//                    abmnStr = pyobj1.callAttr("subABMN", abmn, dtype, shape, 0).toJava(String.class);
//                } else {
//                    int dtypelen1 = dtypelen0 - 1;
//                    //System.out.println("---------------dtypelen1---"+dtypelen1);
//                    int dtypelen2 = dtypelen - dtypelen1;
//                    System.out.println("---------------dtypelen2---" + dtypelen2);
//                    if (dtypelen2 == dtypelen) {
//                        onPause();
//                        dtypelen = 0;
//                        //returnSta = false;
//                        return;
//                    }
//                    dtypelen0 = dtypelen1;
//                    //System.out.println("---------------dtypelen0---"+dtypelen0);
//                    abmnStr = pyobj1.callAttr("subABMN", abmn, dtype, shape, dtypelen2).toJava(String.class);
//                    if (dtypelen2 % boxId == 0) {
//                        boxInx += 1;
//                    }
////                    if(166 % boxId == 0){
////                        boxInx +=1;
////                    }
//                }
//
//
//                String[] abmnlis = null;
//                if (abmnStr.length() > 0) {
//                    abmnlis = abmnStr.split(",");
//                }
//
//                //kSetTxWaveWithParam 3
//                //if (inclickGatherCount == 0) {
//                String abmbinx = "";
//                if (boxInx == 0) {
//                    abmbinx = alis.get(0);
//                } else {
//                    abmbinx = alis.get(boxInx);
//                }
//
//                data = pyobj1.callAttr("onSendParamToMcu", abmbinx, send_frequency_val.getSelectedItemPosition() + 1, packet_indx1, send_voltage_val.getText().toString()).toJava(byte[].class);
//                // SocketUtils.writeMsgByte(data);
//                //}
////                else {
////                    data = pyobj1.callAttr("onSendParamToMcu", "1", send_frequency_val.getSelectedItemPosition() + 1, packet_indx1, "40").toJava(byte[].class);
////
////                }
//                //data = pyobj1.callAttr("onSendParamToMcu", "1", send_frequency_val.getSelectedItemPosition() + 1, packet_indx1, send_voltage_val.getText().toString()).toJava(byte[].class);
//                if (anewSta) {
//                    SocketUtils.writeMsgByte(data);
//                }
//
//                //kClearAllMuxBoxConnect 15
//                data2 = pyobj1.callAttr("clear_mux", clearStrLisAll[0], clearStrLisAll[1], clearStrLisAll[2], clearStrLisAll[3], clearStrLisAll[4],
//                        clearStrLisAll[5], clearStrLisAll[6], clearStrLisAll[7], clearStrLisAll[8], clearStrLisAll[9]).toJava(byte[].class);
//                //kSetMuxBoxConnect 2
//                data3 = pyobj1.callAttr("update_poles_connect", 1 + "," + abmnlis[0], 1 + "," + abmnlis[1],
//                        1 + "," + abmnlis[2], 1 + "," + abmnlis[3]).toJava(byte[].class);
//
//                loding_count = 1;
//
//                try {
//                    if (!startGater) {
//                        Thread.sleep(1);
//                    }
//
//                    if (SocketUtils.success_count < 7) {
//                        onPause();
//                        //System.out.println("===== 挂起=====");
//                    }
//
//                    returnSta = recv_float_array_with_indx(abmnlis);
//                    if (returnSta) {
//                        startCount = 0;
//                        inclickGatherCount += 1;
//                        abmn_indx += 1;
//                        SocketUtils.receiveDataAll = "";
//                        SocketUtils.packet_indx = 0;
//                        SocketUtils.packet_lens = 0;
//                        SocketUtils.packet_lens_old = 0;
//                        SocketUtils.success_count = 1;
//
//                    }
////                    else {
////                        returnSta = recv_float_array_with_indx(abmnlis);
////                        if(returnSta){
////                            returnSta = false;
////                            startCount =0;
////                            inclickGatherCount += 1;
////                            abmn_indx += 1;
////                            SocketUtils.receiveDataAll = "";
////                            SocketUtils.packet_indx = 0;
////                            SocketUtils.packet_lens = 0;
////                            SocketUtils.packet_lens_old = 0;
////                            SocketUtils.success_count = 1;
////                        }
////                    }
//
//                } catch (InterruptedException e) {
//                    throw new RuntimeException(e);
//                } catch (IOException e) {
//                    throw new RuntimeException(e);
//                }
//
//                rec_count_s = 0;
//                //break;
//                //no_id_str = "";
//            }
//        }
//    }
//
//    private void initData() {
//
//        Sends sends = new Sends();
//        Items items = findSelectItem();
//        //sends.setId(1);
//        sends.setItemId(items.getId());
//        sendsService = new SendsService();
//        //sendsService.updade(sends,new Sends());
//        List<Sends> sendlis = sendsService.getSendsLast(sends);
//        if (sendlis.size() > 0) {
//            send_voltage_val.setText(sendlis.get(0).getVoltage());
//            send_repeat_val.setText(sendlis.get(0).getRepeatNum());
//            //send_frequency_val.setText(sendlis.get(0).getSendFrequency());
//            send_frequency_val.setSelection(Integer.parseInt(sendlis.get(0).getSendFrequency()));
//            //send_duration_val.setText(sendlis.get(0).getSendDuration());
//            clear_all_mux_box_connect_val.setText(sendlis.get(0).getBoxaddr());
//        }
//    }
//
//    private Integer findSendCount() {
//        Items items = findSelectItem();
//        sendsService = new SendsService();
//        List<Sends> lis = sendsService.getSends(new Sends(items.getId()));
//        return lis.size();
//    }
//
//    private Integer findItemCount() {
//        itemsService = new ItemsService();
//        List<Items> lis = itemsService.getItems(new Items());
//        return lis.size();
//    }
//
//    private Items findSelectItem() {
//        itemsService = new ItemsService();
//        Items items = new Items();
//        Items items1 = new Items();
//        items.setStatus(1);
//        List<Items> lis = null;
//
//        try {
//            lis = itemsService.getItems(items);
//            items1 = lis.get(0);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return items1;
//    }
//
//    /**
//     * 保存后的弹框
//     */
//    private Boolean showPopupWindow() {
//
//        //设置contentView
//        contentView = LayoutInflater.from(myContext).inflate(R.layout.send_receive_add_pop, null);
//        mPopWindow = new PopupWindow(contentView,
//                ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT, true);
//        mPopWindow.setContentView(contentView);
//        mPopWindow.setTouchable(true); //设置是否响应触摸事件
//        mPopWindow.setFocusable(false);//设置是否能获取焦点（如果控件中药EditText需要设置为true不然无法输入）
//        mPopWindow.setOutsideTouchable(false);
//        setAlpha(0.2f);
//        mChart1 = contentView.findViewById(R.id.send_pop_chart);
//        send_voltage_pop_val = contentView.findViewById(R.id.send_voltage_pop_val);
//        send_repeat_pop_val = contentView.findViewById(R.id.send_repeat_pop_val);
//        send_freq_pop_val = contentView.findViewById(R.id.send_freq_pop_val);
//        receive_duration_pop_val = contentView.findViewById(R.id.receive_duration_pop_val);
//
//        send_voltage_pop_val.setText(send_voltage_val.getText() + "v");
//        send_repeat_pop_val.setText(send_repeat_val.getText() + "次");
//        send_freq_pop_val.setText(sf + "hz");
//        receive_duration_pop_val.setText(send_repeat_val.getText() + "秒");
//
//        //显示PopupWindow
//        View rootview = LayoutInflater.from(myContext).inflate(R.layout.send_receive_add, null);
//
//        mPopWindow.showAtLocation(rootview, Gravity.BOTTOM, 0, 0);
////        mChart1.setOnClickListener(new View.OnClickListener() {
////            @Override
////            public void onClick(View v) {
////                //mPopWindow.setHeight(500);
////                // mPopWindow.showAtLocation(rootview, Gravity.TOP, 0, 0);
////                mChart1.setPivotX(mChart1.getWidth() / 2);
////                mChart1.setPivotY(mChart1.getHeight() / 2);//支点在图片中心
////                mChart1.setRotation(90);
////                ViewGroup.LayoutParams params = mChart1.getLayoutParams();
////                params.width = ScreenUtil.getScreenWidth(myContext);
////                params.height = ScreenUtil.getScreenHeight(myContext);
////                mChart1.setLayoutParams(params);
////            }
////        });
//        //viewHolder.set
//        pop_close = contentView.findViewById(R.id.send_pop_close);
//        pop_close.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (startCount == 1) {
//                    AlertDialog.Builder dialog = new AlertDialog.Builder(myContext);//通过AlertDialog.Builder创建出一个AlertDialog的实例
//
//                    dialog.setTitle("提示");//设置对话框的标题
//                    dialog.setMessage("采集数据中请勿离开页面,否则会中断采集!");//设置对话框的内容
//                    dialog.setCancelable(false);//设置对话框是否可以取消
//                    dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {//确定按钮的点击事件
//
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//                            recv_float_bool = false;
//                            receive_one_field_sta = false;
//                            SocketUtils.success_count = 0;
//                            mPopWindow.dismiss();
//                            setAlpha(1.0f);
//                            SendReceiveAddBackNewActivity.this.finish();
//                        }
//                    });
//                    dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {//取消按钮的点击事件
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//                            dialog.dismiss();
//                        }
//                    });
//                    dialog.show();//显示对话框
//                } else {
//                    recv_float_bool = false;
//                    receive_one_field_sta = false;
//                    SocketUtils.success_count = 0;
//                    mPopWindow.dismiss();
//                    setAlpha(1.0f);
//                    SendReceiveAddBackNewActivity.this.finish();
//                }
//
//                SocketUtils.success_count = 0;
//                try {
//                    queue = null;
//                    data = null;
//                    data2 = null;
//                    data3 = null;
//                    receive_one_field_sta = false;
//                    msg_sueecss_count = 0;
//                    SocketUtils.packet_indx = 0;
//                    //socketUtils.buffer = null;
//                    //SocketUtils.writeMsg("22,M;");
//
//                    //111
//                    Thread.sleep(10);
//                } catch (InterruptedException e) {
//                    throw new RuntimeException(e);
//                }
//                //Toast.makeText(myContext, "关闭 === " + v.getId(), Toast.LENGTH_SHORT).show();
//
////                socketUtils.releaseSocket();
////                socketUtils = null;
//                SocketUtils.receiveDataAll = "";
//
//
//            }
//        });
//
//        //把背景还原
//        mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
//            @Override
//            public void onDismiss() {
//                SocketUtils.success_count = 5;
//                setAlpha(1.0f);
//            }
//        });
//        return true;
//    }
//
////    private void setImageVal(String tx_voltage) {
////        //final ViewHolder viewHolder;
////        bytesData = null;
////        bytesData = pyobj.callAttr("sendCurve", tx_voltage).toJava(byte[].class);
////        mChart1.setImageBitmap(BitmapFactory.decodeByteArray(bytesData, 0, bytesData.length));
////    }
//
//    private void initPython(Context myContext) throws JSONException, InterruptedException {
//        //初始化python环境
//        if (!Python.isStarted()) {
//            Python.start(new AndroidPlatform(myContext));
//        }
//
//        py = Python.getInstance();
//        //调用hello_python.py里面的plot函式
//        pyobj = py.getModule("plotmy");
//        pyobj1 = py.getModule("Send_Param");
//        pyobj2 = py.getModule("Struct_Data");
//        pyobj3 = py.getModule("earth_main");
//        pyobjfft = py.getModule("fft_ui");
//
//    }
//
//    private void setAlpha(float f) {
//        WindowManager.LayoutParams lp = getWindow().getAttributes();
//        lp.alpha = f;
//        getWindow().setAttributes(lp);
//    }
//
//    public class ViewHolder {
//
//        public ImageView mChart1;
//
//        public ViewHolder(View view, int position) {
//            mChart1 = view.findViewById(R.id.send_pop_chart);
//
//        }
//
//    }
//
//
//}